package com.service.impl;

import com.dao.Supplier_infoDao;
import com.dao.impl.Supplier_infoDaoImpl;
import com.pojo.Supplier_info;
import com.service.Supplier_infoService;
import com.util.PageUtil;

import java.util.List;

public class Supplier_infoServiceImpl implements Supplier_infoService {

    Supplier_infoDao supplierInfoDao = new Supplier_infoDaoImpl();

    /***
     * 获取每页供应商列表、页码、页面大小、总数、总页数
     * @param pageIndex
     * @param pageSize
     * @param search
     * @return
     */
    @Override
    public PageUtil<Supplier_info> findPageSupplierList(int pageIndex, int pageSize, String search) {
        List<Supplier_info> pageSupplierList = supplierInfoDao.findPageSupplierList(pageIndex, pageSize, search);
        int allSupplierCount = supplierInfoDao.findAllSupplierCount(search);
        int pageCount = (int) Math.ceil((double) allSupplierCount / pageSize);
        PageUtil<Supplier_info> supplierInfoPageUtil = new PageUtil<>(pageIndex, pageSize, allSupplierCount, pageCount, pageSupplierList);
        return supplierInfoPageUtil;
    }

    /***
     * 获取单个供应商信息、编辑页面
     * @param id
     * @return
     */
    @Override
    public Supplier_info findSupplierById(int id) {
        return supplierInfoDao.findSupplierById(id);
    }

    /***
     * 编辑更新供应商
     * @param supplierInfo
     * @return
     */
    @Override
    public int updateSupplier(Supplier_info supplierInfo) {
        return supplierInfoDao.updateSupplier(supplierInfo);
    }

    /***
     * 添加供应商
     * @param supplierInfo
     * @return
     */
    @Override
    public int addSupplier(Supplier_info supplierInfo) {
        return supplierInfoDao.addSupplier(supplierInfo);
    }

    /***
     * 删除供应商 status 0是有效 1是无效
     * @param id
     * @return
     */
    @Override
    public int delSupplier(int id) {
        return supplierInfoDao.delSupplier(id);
    }

    /***
     * 公共方法设置供应商对象的属性
     * @param ids
     * @return
     */
    @Override
    public int delSuppliers(String ids) {
        return supplierInfoDao.delSuppliers(ids);
    }
}
